import axios from 'axios';

const API_URL = 'http://localhost:8000/api/goods/';  // 确保后端接口地址正确

export const getGoods = () => {
  return axios.get(API_URL).then(response => response.data);
};

// goods.js
export const createGood = (good) => {
    return axios.post(API_URL, good).then(response => response.data);
  };

export const updateGood = (id, good) => {
  return axios.put(`${API_URL}${id}/`, good).then(response => response.data);
};

export const deleteGood = (id) => {
  return axios.delete(`${API_URL}${id}/`).then(response => response.data);
};

export const updateShelves = (id, is_shelves, quantity) => {
  return axios.get(`${API_URL}${id}/update_shelves/`, {
    params: {
      is_shelves,
      quantity
    }
  }).then(response => response.data);
};
export const changeGoods = (id, name, price) => {
  return axios.post(`${API_URL}${id}/change_goods/`, {
    name,
    price
  }).then(response => response.data);
};
// // 获取所有商品
// axios.get('/api/goods/')
//   .then(response => {
//     this.allGoods = response.data;
//   });

// 根据状态过滤商品
// axios.get('/api/goods/', {
//   params: { on_shelves: true }
// })
//   .then(response => {
//     this.filteredGoods = response.data;
//   });

//   // 上架或下架商品
// axios.put(`/api/goods/${id}/toggle_status/`)
// .then(response => {
//   console.log('商品状态已更新');
// });